#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    initTimer();
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    timeCounter.start();
    timer.stop();
    timer.start();
}

void Widget::on_timer_timeout()
{
    qDebug("time: %d\n", timeCounter.elapsed());
    ui->timerEt->setText(QString::number(timeCounter.elapsed() / 1000).append(" s"));
    ui->timeCounterEt->setText(QString::number(timeCounter.elapsed()));
}

void Widget::initTimer()
{
    timer.stop();
    timer.setInterval(1000);

    QObject::connect(&timer, SIGNAL(timeout()), SLOT(on_timer_timeout()));
}

void Widget::on_pushButton_2_clicked()
{
    ui->timeCounterEt->setText(QString::number(timeCounter.elapsed()));
    timer.stop();
}
